package www.bplead.com.mydemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import www.bplead.com.mydemo.R;

/**
 * Created by wangyangzi on 2016/10/20.
 */
public class StudentOptionActivity extends Activity implements View.OnClickListener {
    int[] classIds = {1,2,3,4,5};
    String[] classNames = {"高一(1)班","高一(2)班","高一(3)班","高一(4)班","高一(5)班"};
    int[] courseIds = {1,2,3,4,5,6,7};
    String[] courseNames = {"语文","数学","英语","化学","物理","政治","历史"};

    int OPTION_RESULT_CODE_CLASS = 1;
    int OPTION_RESULT_CODE_COURSE = 2;

    ListView optionListView;
    ArrayAdapter<String> adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.student_option);

        final String optionType = getIntent().getStringExtra("option_type");

        optionListView = (ListView) this.findViewById(R.id.student_info_option_lv);
        if("class".equals(optionType)){
            adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,classNames);
        }else if("course".equals(optionType)){
            adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,courseNames);
        }
        optionListView.setAdapter(adapter);


        optionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                if("class".equals(optionType)){
                    intent.putExtra("id",classIds[position]);
                    intent.putExtra("name",classNames[position]);
                    StudentOptionActivity.this.setResult(OPTION_RESULT_CODE_CLASS,intent);
                }else if("course".equals(optionType)){
                    intent.putExtra("id",courseIds[position]);
                    intent.putExtra("name",courseNames[position]);
                    StudentOptionActivity.this.setResult(OPTION_RESULT_CODE_COURSE,intent);
                }
                StudentOptionActivity.this.finish();
            }
        });

    }

    @Override
    public void onClick(View v) {

    }
}
